package com.mvc.listener;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.mvc.config.ConfigBean;
import com.mvc.config.XmlBean;
import com.mvc.util.AnnocationParse;
import com.mvc.util.XmlParser;

public class MvcConfigListener implements ServletContextListener {

	public void contextInitialized(ServletContextEvent sce) {
		System.out.println("系统信息开始加载！");
		ServletContext sc = sce.getServletContext();
		String mvc = sc.getInitParameter("mvc-config");
		String realPath = sc.getRealPath("\\");
		XmlBean xmlBean = XmlParser.parser(realPath + mvc);
		
		AnnocationParse anocationParse = new AnnocationParse(xmlBean.getScanPkg());
		Map<String, ConfigBean> beans = anocationParse.getConfigBeans();
		
		sc.setAttribute("mvcConfig", beans);
		System.out.println("系统信息加载完毕！");
	}

	public void contextDestroyed(ServletContextEvent sce) {
		System.out.println("系统信息注销！");
	}

}
